Skip to content

fix(release): fail loudly when GitHub release asset is missing#232

Open
adekbadek wants to merge 2 commits intotrunkfrom
fix/release-fail-on-missing-asset
Open

fix(release): fail loudly when GitHub release asset is missing#232
adekbadek wants to merge 2 commits intotrunkfrom
fix/release-fail-on-missing-asset

Conversation

@adekbadek
Copy link
Copy Markdown
Member

All Submissions:

Changes proposed in this Pull Request:

@semantic-release/github silently ignores release assets whose path cannot be read on disk – it emits a single warning and then publishes the GitHub release anyway, with no attached archive. This is exactly what happened to newspack-ads v3.10.2: the legacy scripts/release.js interpolated process.env.CIRCLE_PROJECT_REPONAME to undefined under GitHub Actions, the asset path resolved to ./release/undefined.zip, the file did not exist, and the v3.10.2 release shipped without a ZIP. The bug was only noticed after the release was already public.

This PR closes that failure mode in scripts/github/release.js so a similar misconfiguration cannot silently produce an asset-less release again:

  • The script now hard-fails at startup if GITHUB_REPOSITORY is unset, rather than falling back to the placeholder string 'unknown' and producing an unknown.zip asset path that will never match anything on disk.
  • A new local plugin (scripts/github/verify-release-asset.js) is appended to the prepare lifecycle. It runs after release:archive is invoked by semantic-release-version-bump and throws if the expected ./release/<repo>.zip is not present. Because it throws during prepare, semantic-release aborts the run before the publish lifecycle, so no GitHub release is created without the asset attached.

The behavior on a successful release is unchanged – the verification plugin just logs an OK line when the file is present.

How to test the changes in this Pull Request:

The most realistic verification is a dry-run release in a consumer plugin. Using newspack-ads (or any plugin that consumes newspack-scripts via the reusable workflow) on a throwaway branch:

  1. Point the consumer's newspack-scripts dependency at this branch (github:Automattic/newspack-scripts#fix/release-fail-on-missing-asset) and run npm install.
  2. Happy path – Run the release flow end-to-end (e.g. trigger the release workflow on a test branch, or run npm run release locally with GITHUB_ACTIONS=true GITHUB_REPOSITORY=Automattic/newspack-ads set and a valid token). Confirm the new log line [verify-release-asset] OK: …/release/newspack-ads.zip appears and the GitHub release is published with the ZIP attached, exactly as before.
  3. Missing-asset path – Temporarily break the consumer's release:archive script (e.g. point its output at a different filename, or comment out the zip line). Re-run the release. Confirm semantic-release aborts during prepare with the error Release asset not found at …/release/<repo>.zip and that no GitHub release tag is created. This is the regression we are guarding against.
  4. Missing GITHUB_REPOSITORY – Run node scripts/github/release.js --files=newspack-ads.php with GITHUB_REPOSITORY unset. Confirm it exits with code 1 and prints the GITHUB_REPOSITORY is not set message before semantic-release is even constructed.
  5. Verify nothing changes for non-GitHub-Actions consumers: bin/newspack-scripts.js only routes to scripts/github/release.js when GITHUB_ACTIONS=true, so the legacy scripts/release.js code path is untouched.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Hard-fail at startup if GITHUB_REPOSITORY is unset, and add a verification
plugin that aborts semantic-release before publish if the release ZIP is
not on disk. Closes a gap where @semantic-release/github silently ignores
missing assets, which previously allowed releases to be published with no
attached archive.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the GitHub Actions release flow to prevent publishing a GitHub release without the expected ZIP asset when the archive path is wrong or the archive step fails.

Changes:

  • Fail early in scripts/github/release.js when GITHUB_REPOSITORY is not set (instead of falling back to unknown).
  • Add a local semantic-release prepare plugin that verifies ./release/<repo>.zip exists before publishing.
  • Refactor the GitHub release asset path to use a single releaseAssetPath variable.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
scripts/github/verify-release-asset.js Adds a semantic-release prepare plugin to assert the expected ZIP archive exists before publish.
scripts/github/release.js Enforces GITHUB_REPOSITORY presence and appends the verification plugin to prepare to avoid asset-less releases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/github/release.js Outdated
Comment thread scripts/github/verify-release-asset.js
Comment thread scripts/github/verify-release-asset.js
Comment thread scripts/github/verify-release-asset.js Outdated
Reject malformed GITHUB_REPOSITORY values (not in owner/repo form) so a
value like "foo" no longer slips through and produces undefined.zip.
Switch the verification plugin to utils.log for output consistency.
@adekbadek adekbadek marked this pull request as ready for review April 15, 2026 10:12
@adekbadek adekbadek requested a review from a team as a code owner April 15, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants